# -*- coding: utf-8 -*-
# @Time : 2025/1/23 16:58
# @Author : debbyszhang
# @File : conftest.py
# @desc :
import time

import pytest
from playwright.sync_api import sync_playwright

from config import settings
from pageObject.login_page import LoginPage


@pytest.fixture(scope="module", autouse=True)
def page():
    with sync_playwright() as p:
        # browser = p.chromium.launch(headless=True) # 静默运行
        print("settings.HEAD_LESS: ", settings.HEAD_LESS)
        browser = p.chromium.launch(headless=settings.HEAD_LESS)  # 打开浏览器运行
        context = browser.new_context()
        page = context.new_page()
        login_page = LoginPage(page)
        login_page.login(settings.USER_RELAY, settings.USER_RELAY_PASSWORD)
        yield page
        # 后置钩子：关闭浏览器
        time.sleep(1)
        page.close()
        context.close()
        browser.close()
